home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
cool
/
ge_cool.lha
/
GE_COOL2.1
/
man
/
oldman3
/
Random.3T
< prev
next >
Wrap
Text File
|
1992-06-26
|
4KB
|
116 lines
.TH RANDOM
.SH NAME
Random A portable, user-selectable random number generator
.SH SYNOPSIS
\f3#include \f1<cool/Random.h>
.SH DESCRIPTION
The Random class provides several general-purpose random number generators
with features similar to those as described in Chapter 7 of
\f2Numerical Recipes in C\f1,
written by William T. \p
Vetterling. The ANSI C draft standard specifies
the
rand
function that allows an application to obtain successive random numbers in
a sequence by repeated calls. However, system-supplied random number generators
in the form of the
rand
function are generally of poor quality, particularly
when true random distribution over a range is important. Specifically, system
random number generators are almost always linear congruential generators whose
period is not very large. The ANSI C draft specification only requires a
modulus of 32767, which can be disastrous for such uses as a Monte Carlo
integration over 10^6 points.
.PP
The
Random
class allows an application to select one of five types of random
number generators based upon the usage requirements. Each generator function
has different characteristics and all are defined to be of type
RNG_TYPE .
The
SIMPLE
and
SHUFFLE
functions use the system \p
rand
function, while the
ONE_CONGRUENTIAL, THREE_CONGRUENTIAL,
and \p
SUBTRACTIVE
functions are
self-contained, portable implementations. Following are descriptions of each
generator function.
.PP
.TP .2i
\(bu
\f3SIMPLE\f1 When speed is the predominant concern, this function uses the
system-supplied \f3rand\f1 function. Although sequential correlation of successive
random values is a high probability, this function at least ensures that the
value's least significant bits are as random as the most significant bits. In
many system random generator functions, the value's least significant bits are
often less random than the most significant bits.
.TP
\(bu
\f3SHUFFLE\f1 This function uses the \f3rand\f1 function and a shuffling procedure.
Random numbers are stored in a buffer and selected randomly to break up
sequential correlation in the system-supplied function.
.TP
\(bu
\f3ONE_CONGRUENTIAL\f1 This self-contained function uses one linear congruential
generator instead of the \f3rand\f1 function to implement a portable random number
generator. This guarantees no sequential correlation between the random values
returned.
.TP
\(bu
\f3THREE_CONGRUENTIAL\f1 This portable function uses three linear congruential
generators to implement a random number generator whose period is essentially
infinite and has no sequential correlations.
.TP
\(bu
\f3SUBTRACTIVE\f1 This function implements a portable random number generator that does not use linear congruential generators, but rather an original
subtractive member function as suggested in Volume 2 of \f2The Art of Computer
Programming\f1, written by Donald Knuth.
.SH Base Classes
.SH Friend Classes
None
.SH Constructor
.TP
\f3Random (RNG_TYPE \f2r_type\f3, int \f2seed \f1= 1\f3, float \f2lower \f1= 0.0,\f3 float \f2upper \f1= 100.0\f3);\f1
Constructor for a floating-point random number generator that initializes the
selected random number generator function with the user-supplied \f2seed\f1 value.
.SH Member Functions
.TP
inline double next ();
Returns the next double floating-point random number within the user-specified
range.
.TP
nline int get_seed () const;
Returns the seed value for the currently-selected random number generator.
.TP
\f3inline void set_rng (RNG_TYPE \f2r_type\f3);\f1
Sets the random number generator function to the type selected by the user and
reinitializes the state.
.TP
\f3inline void set_seed (int \f2seed\f3);\f1
Sets the seed value for the currently-selected random number generator function
and reinitilizes the state.
.SH COPYRIGHT
Copyright (C) 1991 Texas Instruments Incorporated.
Permission is granted to any individual or institution to use, copy, modify,
and distribute this software, provided that this complete copyright and
permission notice is maintained, intact, in all copies and supporting
documentation.
Texas Instruments Incorporated provides this software "as is" without
express or implied warranty.